package ysq.weixin.util;


import ysq.weixin.model.info.OAuthScope;
import ysq.xyg.util.BaseConstant;
import ysq.xyg.util.BaseUtil;

/**
 * 微信基础URL
 */
public class WxUrlUtil {

    //获取token URL 接口
    public static String getTokenUrl(String appId,String appSecret){
        return String.format(TOKEN, appId, appSecret);
    }
    //获取菜单创建接口
    public static String getMenuCreateUrl(String token){
        return String.format(MENU_CREATE, token);
    }
    //获取菜单删除接口
    public static String getMenuDeleteUrl(String token){
        return String.format(MENU_DELETE, token);
    }
    //网页授权OAuth2.0获取code
    public static String getOAuthCodeUrl(String appId ,String redirectUrl ,String scope ,String state){
        if(OAuthScope.Userinfo.toString().equals(scope)){
            state= BaseConstant.OAUTH_USERINFO+state;
        }else {
            state=BaseConstant.OAUTH_BASE+state;
        }
        return String.format(GET_OAUTH_CODE, appId, BaseUtil.urlEnodeUTF8(redirectUrl), "code", scope, state);
    }
    //网页授权OAuth2.0获取token
    public static String getOAuthTokenUrl(String appId ,String appSecret ,String code ){
        return String.format(GET_OAUTH_TOKEN, appId, appSecret, code);
    }
    //网页授权OAuth2.0获取用户信息
    public static String getOAuthUserinfoUrl(String token ,String openid){
        return String.format(GET_OAUTH_USERINFO, token, openid);
    }
    //获取发送模板消息 url
    public static String getSendTemplateMessageUrl(String token){
        return String.format(SEND_TEMPLATE_MESSAGE, token);
    }
    //获取js ticket url
    public static String getJsApiTicketUrl(String token){
        return String.format(GET_JSAPI_TICKET, token);
    }
    //获取微信支付-统一下单接口 url
    public static String getPayNoticeUrl(){
        return PAY_NOTICE_URL;
    }
    //微信企业转账
    public static String getPayTransfers(){
        return PAY_TRANSFERS_URL;
    }








    //token 接口
    protected static final String TOKEN = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    //创建菜单
    private static final String MENU_CREATE = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s";
    //删除菜单
    private static final String MENU_DELETE = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s";
    //网页授权OAuth2.0获取code
    private static final String GET_OAUTH_CODE = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=%s&scope=%s&state=%s#wechat_redirect";

    //网页授权OAuth2.0获取token
    private static final String GET_OAUTH_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";

    //网页授权OAuth2.0获取用户信息
    private static final String GET_OAUTH_USERINFO = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN";
    //js ticket
    private static final String GET_JSAPI_TICKET="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";
    //模板消息接口
    private static final String SEND_TEMPLATE_MESSAGE = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s";
    //微信支付-统一下单接口
    public final static String  PAY_NOTICE_URL="https://api.mch.weixin.qq.com/pay/unifiedorder";
    //微信企业转账
    public final static String  PAY_TRANSFERS_URL="https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
}
